package com.example.mall.web.controller;

import com.example.mall.domain.HotProductRecommendations;
import com.example.mall.dto.HotProductRecommendationsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.HotProductRecommendationsQuery;
import com.example.mall.query.PageDTO;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IHotProductRecommendationsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hotProductRecommendations")
public class HotProductRecommendationsController {

    @Autowired
    public IHotProductRecommendationsService hotProductRecommendationsService;

    /**
     * 分页查询热门商品推荐表信息
     * @param hotProductRecommendationsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询热门商品推荐表信息",notes = "分页查询热门商品推荐表信息",httpMethod = "GET")
    public JSONResult queryPage(HotProductRecommendationsQuery hotProductRecommendationsQuery){
        PageDTO<HotProductRecommendationsDto> hotProductRecommendationsDtoPageDTO = hotProductRecommendationsService.queryPage(hotProductRecommendationsQuery);
        return JSONResult.success("查询成功",hotProductRecommendationsDtoPageDTO);
    }

    /**
     * 根据id查询热门商品推荐表信息
     * @param recommendId
     * @return
     */
    @GetMapping("query/{recommendId}")
    @ApiOperation(value = "根据id查询热门商品推荐表信息",notes = "根据id查询热门商品推荐表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("id")Long recommendId){
        //1.根据id查询用户信息
        if (recommendId == null){
            throw new GlobalCustomerException(ErrorEnumCode.RECOMMENDID_NOT_ID);
        }
        HotProductRecommendations hotProductRecommendations = hotProductRecommendationsService.getById(recommendId);
        return JSONResult.success("查询成功",hotProductRecommendations);
    }

    /**
     * 根据id查询热门商品推荐表信息
     * @param recommendId
     * @return
     */
    @GetMapping("queryHotProductRecommendationsById/{recommendId}")
    @ApiOperation(value = "根据id查询热门商品推荐表信息",notes = "根据id查询热门商品推荐表信息",httpMethod = "GET")
    public JSONResult queryHotProductRecommendationsById(@PathVariable("recommendId")Long recommendId){
        //1.根据id查询用户信息
        if (recommendId == null){
            throw new GlobalCustomerException(ErrorEnumCode.RECOMMENDID_NOT_ID);
        }
        HotProductRecommendations hotProductRecommendations = hotProductRecommendationsService.queryHotProductRecommendationsById(recommendId);
        return JSONResult.success("查询成功",hotProductRecommendations);
    }

    /**
     * 查询全部热门商品推荐表信息
     * @param
     * @return
     */
    @GetMapping("queryHotProductRecommendationsList")
    @ApiOperation(value = "查询全部热门商品推荐表信息",notes = "查询全部热门商品推荐表信息",httpMethod = "GET")
    public JSONResult queryHotProductRecommendationsList(){
        List<HotProductRecommendations> hotProductRecommendations = hotProductRecommendationsService.queryHotProductRecommendationsList();
        return JSONResult.success("查询成功",hotProductRecommendations);
    }

    /**
     * 新增热门商品推荐表
     * @param hotProductRecommendationsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增热门商品推荐表",notes = "新增热门商品推荐表",httpMethod = "POST")
    public JSONResult insert(@RequestBody HotProductRecommendationsDto hotProductRecommendationsDto){
        hotProductRecommendationsService.insert(hotProductRecommendationsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改热门商品推荐表信息
     * @param hotProductRecommendationsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改热门商品推荐表信息",notes = "修改热门商品推荐表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody HotProductRecommendationsDto hotProductRecommendationsDto){
        hotProductRecommendationsService.update(hotProductRecommendationsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除热门商品推荐表信息
     * @param recommendId
     * @return
     */
    @PostMapping("delete/{recommendId}")
    @ApiOperation(value = "删除热门商品推荐表信息",notes = "删除热门商品推荐表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("recommendId") Long recommendId) {
        hotProductRecommendationsService.delete(recommendId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除热门商品推荐表信息
     * @param recommendIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除热门商品推荐表信息",notes = "批量删除热门商品推荐表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> recommendIds) {
        hotProductRecommendationsService.deleteBatch(recommendIds);
        return JSONResult.success("批量删除成功");
    }
}
